package com.black.web.controller.my;

import com.black.app.domain.req.my.MyUserPostEditReq;
import com.black.app.domain.req.my.MyUserPostInformationEditReq;
import com.black.app.domain.req.my.MyUserPostInformationReq;
import com.black.app.domain.resp.my.MyUserPostInformationResp;
import com.black.app.domain.resp.my.MyUserPostResp;
import com.black.app.service.AppUserService;
import com.black.app.service.my.AppMyUserinfoService;
import com.black.common.core.controller.BaseController;
import com.black.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api(tags="我的帖子相关Api-后台")
@RestController
@RequestMapping("/admin/my")
public class AdminMyController extends BaseController {

    @Autowired
    private AppUserService appUserService;

    @Autowired
    private AppMyUserinfoService appMyUserinfoService;

    @ApiOperation(value = "分页查询首页信息")
    @GetMapping(value = "/information")
    @PreAuthorize("@ss.hasPermi('my:post:query')")
    public R<PageInfo<MyUserPostInformationResp>> postInformation(MyUserPostInformationReq req){
        PageInfo<MyUserPostInformationResp> Resp = this.appUserService.postInformation(req);
        return R.ok(Resp);
    }

    @ApiOperation(value = "修改首页信息")
    @PreAuthorize("@ss.hasPermi('my:post:edit')")
    @PutMapping(value = "/edit/information")
    public R edit(@RequestBody @Valid MyUserPostInformationEditReq req){
        boolean result=this.appUserService.edit(req);
        return super.isSuccess(result);
    }


    @ApiOperation(value = "根据用户id进行查询帖子首页信息")
    @PreAuthorize("@ss.hasPermi('my:post:query')")
    @GetMapping(value = "/post/home/{userId}")
    public R<MyUserPostInformationResp> postHomeByUserId(@PathVariable(value = "userId") Long userId){
        MyUserPostInformationResp Resp = this.appUserService.postInformationByUserId(userId);
        return R.ok(Resp);
    }

    @ApiOperation(value = "分页用户帖子查询")
    @PreAuthorize("@ss.hasPermi('my:content:query')")
    @GetMapping(value = "/post")
    public R<PageInfo<MyUserPostResp>> post(MyUserPostInformationReq req){
        PageInfo<MyUserPostResp> Resp = this.appUserService.post(req);
        return R.ok(Resp);
    }

    @ApiOperation(value = "通过帖子id进行查询帖子内容")
    @PreAuthorize("@ss.hasPermi('my:content:query')")
    @GetMapping(value = "/post/{id}")
    public  R<MyUserPostResp> postByUserId(@PathVariable(value = "id") Long id){
        MyUserPostResp Resp = this.appUserService.postByid(id);
        return R.ok(Resp);
    }

    @ApiOperation(value = "修改帖子内容")
    @PreAuthorize("@ss.hasPermi('my:content:edit')")
    @PutMapping(value = "/revise/post")
    public R revise(@RequestBody @Valid MyUserPostEditReq req){
        boolean result=this.appUserService.revise(req);
        return super.isSuccess(result);
    }

    @ApiOperation(value = "删除帖子")
    @PreAuthorize("@ss.hasPermi('my:content:remove')")
    @DeleteMapping(value = "/delete/post/{ids}")
    public R delete(@PathVariable(value = "ids") Long[] id){
        boolean result=this.appMyUserinfoService.removePost(id);
        return super.isSuccess(result);
    }
}
